<?php

class Zend_View_Helper_Mynotes extends Zend_View_Helper_Abstract
{
    const PROFILER_NAMESPACE = 'prf';

    public function mynotes()
    {
        return $this;
    }

    public function isProfilerEnabled()
    {
        $session = new Zend_Session_Namespace(self::PROFILER_NAMESPACE);
        return 1 === $session->val;
    }

    public function digest()
    {
        $table = new Application_Model_DbTable_MainTask();
        $rows = $table->fetchAll()->toArray();
        $digest = array();

        foreach ($rows as $row) {
            $digest[] = new Application_Model_Thing($row);
        }

        usort($digest, function ($a, $b) {
            /** @var $a Application_Model_Thing */
            /** @var $b Application_Model_Thing */
            if ($a->getPriority() > $b->getPriority()) {
                return 1;
            }

            return 0;
        });

        $this->view->digest = $digest;
        return $this->view->render('digest.phtml');
    }

}